package com.xtayfjpk.zookeeper.test.master_workers.callback.recovery;

import java.util.List;

import org.apache.log4j.Logger;
import org.apache.zookeeper.KeeperException;
import org.apache.zookeeper.KeeperException.Code;

import com.xtayfjpk.zookeeper.test.master_workers.callback.BaseChildrenCallback;
import com.xtayfjpk.zookeeper.test.master_workers.recovery.RecoveredAssignments;

public class AssignedWorkersCallback extends BaseChildrenCallback {
	private final static Logger LOGGER = Logger.getLogger(AssignedWorkersCallback.class);
	private RecoveredAssignments assignments;
	
	public AssignedWorkersCallback(RecoveredAssignments recoveredAssignments) {
		this.assignments = recoveredAssignments;
	}
	
	
	@Override
	protected void connectionLossCaseAction(int rc, String path, Object ctx,
			List<String> children) {
		assignments.getAssignedWorkers();
	}
	
	@Override
	protected void okCaseAction(int rc, String path, Object ctx,
			List<String> children) {
		assignments.setAssignedWorkerList(children);
		assignments.getWorkers(children);
	}
	
	@Override
	protected void defaultCaseAction(int rc, String path, Object ctx,
			List<String> children) {
		LOGGER.error("getChildren failed",  KeeperException.create(Code.get(rc), path));
        assignments.getCb().recoveryComplete(com.xtayfjpk.zookeeper.test.master_workers.recovery.RecoveryCallback.FAILED, null);
	}

}
